package org.syntaxlisp.core.match.tree;

import org.syntaxlisp.core.utils.Copyable;
import org.syntaxlisp.core.utils.ListTreeVal;
import lombok.Getter;
import lombok.Setter;

/**
 * @author HuangYijun
 * @data 2024-02-01 11:22
 **/
@Getter
public class RepeatStartFrame implements Copyable<RepeatStartFrame>, ListTreeVal {

    // todo:
    @Setter
    @Getter
    private NewMatchSeqNode latestPreMatchBodySeqNode;

    private final int downSourceLayer;

    private final int startOffset;

    private String key;

    private Integer keyCode;

    public RepeatStartFrame (int downSourceLayer, int startOffset) {
        this.downSourceLayer = downSourceLayer;
        this.startOffset = startOffset;
    }

    public RepeatStartFrame copy () {
        return new RepeatStartFrame(downSourceLayer, startOffset);
    }

    @Override
    public String getUniqueKey() {
        if (key == null) {
            key = startOffset + "-" + downSourceLayer;
        }
        return key;
    }

    @Override
    public Integer getHashKey() {
        if (keyCode == null) {
            keyCode = getUniqueKey().hashCode();
        }
        return keyCode.hashCode();
    }

    @Override
    public Object getSrcVal() {
        return this;
    }
}
